home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / kh_gdi.zip / GD_DMABD.CPP < prev    next >
C/C++ Source or Header  |  1996-05-11  |  5KB  |  176 lines

  1. /*  Project gdi_demo
  2.     
  3.     Copyright ⌐ 1995. All Rights Reserved.
  4.  
  5.     SUBSYSTEM:    gdi_demo.exe Application
  6.     FILE:         gd_dmabd.cpp
  7.     AUTHOR:       S.Vartanov
  8.  
  9.  
  10.     OVERVIEW
  11.     ========
  12.     Source file for implementation of gdi_demoAboutDlg (TDialog).      
  13. */
  14.  
  15.  
  16. #include <owl\owlpch.h>
  17. #pragma hdrstop
  18.  
  19. #if !defined(__FLAT__)
  20. #include <ver.h>
  21. #endif
  22.  
  23. #include "gd_dmapp.h"
  24. #include "gd_dmabd.h"
  25.  
  26.  
  27. ProjectRCVersion::ProjectRCVersion (TModule *module)
  28. {
  29.     char    appFName[255];
  30.     char    subBlockName[255];
  31.     DWORD   fvHandle;
  32.     UINT    vSize;
  33.  
  34.     FVData = 0;
  35.  
  36.     module->GetModuleFileName(appFName, sizeof(appFName));
  37.     OemToAnsi(appFName, appFName);
  38.     DWORD dwSize = ::GetFileVersionInfoSize(appFName, &fvHandle);
  39.     if (dwSize) {
  40.         FVData  = (void FAR *)new char[(UINT)dwSize];
  41.         if (::GetFileVersionInfo(appFName, fvHandle, dwSize, FVData)) {
  42.             // Copy string to buffer so if the -dc compiler switch (Put constant strings in code segments)
  43.             // is on VerQueryValue will work under Win16.  This works around a problem in Microsoft's ver.dll
  44.             // which writes to the string pointed to by subBlockName.
  45.             strcpy(subBlockName, "\\VarFileInfo\\Translation"); 
  46.             if (!::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&TransBlock, &vSize)) {
  47.                 delete FVData;
  48.                 FVData = 0;
  49.             } else
  50.                 // Swap the words so wsprintf will print the lang-charset in the correct format.
  51.                 *(DWORD *)TransBlock = MAKELONG(HIWORD(*(DWORD *)TransBlock), LOWORD(*(DWORD *)TransBlock));
  52.         }
  53.     }
  54. }
  55.  
  56.  
  57. ProjectRCVersion::~ProjectRCVersion ()
  58. {
  59.     if (FVData)
  60.         delete FVData;
  61. }
  62.  
  63.  
  64. bool ProjectRCVersion::GetProductName (LPSTR &prodName)
  65. {
  66.     UINT    vSize;
  67.     char    subBlockName[255];
  68.  
  69.     if (FVData) {
  70.         wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"ProductName");
  71.         return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&prodName, &vSize) : false;
  72.     } else
  73.         return false;
  74. }
  75.  
  76.  
  77. bool ProjectRCVersion::GetProductVersion (LPSTR &prodVersion)
  78. {
  79.     UINT    vSize;
  80.     char    subBlockName[255];
  81.  
  82.     if (FVData) {
  83.         wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"ProductVersion");
  84.         return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&prodVersion, &vSize) : false;
  85.     } else
  86.         return false;
  87. }
  88.  
  89.  
  90. bool ProjectRCVersion::GetCopyright (LPSTR ©right)
  91. {
  92.     UINT    vSize;
  93.     char    subBlockName[255];
  94.  
  95.     if (FVData) {
  96.         wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"LegalCopyright");
  97.         return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)©right, &vSize) : false;
  98.     } else
  99.         return false;
  100. }
  101.  
  102.  
  103. bool ProjectRCVersion::GetDebug (LPSTR &debug)
  104. {
  105.     UINT    vSize;
  106.     char    subBlockName[255];
  107.  
  108.     if (FVData) {
  109.         wsprintf(subBlockName, "\\StringFileInfo\\%08lx\\%s", *(DWORD *)TransBlock, (LPSTR)"SpecialBuild");
  110.         return FVData ? ::VerQueryValue(FVData, subBlockName, (void FAR* FAR*)&debug, &vSize) : false;
  111.     } else
  112.         return false;
  113. }
  114.  
  115.  
  116. //{{gdi_demoAboutDlg Implementation}}
  117.  
  118.  
  119. //////////////////////////////////////////////////////////
  120. // gdi_demoAboutDlg
  121. // ==========
  122. // Construction/Destruction handling.
  123. gdi_demoAboutDlg::gdi_demoAboutDlg (TWindow *parent, TResId resId, TModule *module)
  124.     : TDialog(parent, resId, module)
  125. {
  126.     // INSERT>> Your constructor code here.
  127. }
  128.  
  129.  
  130. gdi_demoAboutDlg::~gdi_demoAboutDlg ()
  131. {
  132.     Destroy();
  133.  
  134.     // INSERT>> Your destructor code here.
  135. }
  136.  
  137.  
  138. void gdi_demoAboutDlg::SetupWindow ()
  139. {
  140.     LPSTR prodName = 0, prodVersion = 0, copyright = 0, debug = 0;
  141.  
  142.     // Get the static text for the value based on VERSIONINFO.
  143.     TStatic *versionCtrl = new TStatic(this, IDC_VERSION, 255);
  144.     TStatic *copyrightCtrl = new TStatic(this, IDC_COPYRIGHT, 255);
  145.     TStatic *debugCtrl = new TStatic(this, IDC_DEBUG, 255);
  146.  
  147.     TDialog::SetupWindow();
  148.  
  149.     // Process the VERSIONINFO.
  150.     ProjectRCVersion applVersion(GetModule());
  151.  
  152.     // Get the product name and product version strings.
  153.     if (applVersion.GetProductName(prodName) && applVersion.GetProductVersion(prodVersion)) {
  154.         // IDC_VERSION is the product name and version number, the initial value of IDC_VERSION is
  155.         // the word Version (in whatever language) product name VERSION product version.
  156.         char    buffer[255];
  157.         char    versionName[128];
  158.  
  159.         buffer[0] = '\0';
  160.         versionName[0] = '\0';
  161.  
  162.         versionCtrl->GetText(versionName, sizeof(versionName));
  163.         wsprintf(buffer, "%s %s %s", prodName, versionName, prodVersion);
  164.  
  165.         versionCtrl->SetText(buffer);
  166.     }
  167.  
  168.     //Get the legal copyright string.
  169.     if (applVersion.GetCopyright(copyright))
  170.         copyrightCtrl->SetText(copyright);
  171.  
  172.     // Only get the SpecialBuild text if the VERSIONINFO resource is there.
  173.     if (applVersion.GetDebug(debug))
  174.         debugCtrl->SetText(debug);
  175. }
  176.